package fr.controller.actions;

import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionSupport;
import fr.beans.Config;
import fr.beans.User;
import fr.model.dao.Hib.IDaoUserHB;


/**
 * @author Altenide
 * Core Action controler Struts
 */
public class CoreControllerAction extends ActionSupport {
	
	
	// ================   generics attributs =============== //

	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 1841615719116587145L;


	/**
	 * The logger.
	 */
	private static final  Logger LOG 
	= Logger.getLogger(CoreControllerAction.class);


	// ================  Déclaration des services Dao =============== //


	/**
	 * Interface Dao for user.
	 */
	private IDaoUserHB iDaoUserHB;


	/**
	 * Constructor.
	 * @param piDaoUserHB
	 *    piDaoUserHB for injection by spring
	 */
	
	public CoreControllerAction(final IDaoUserHB piDaoUserHB) {
		super();
		this.iDaoUserHB = piDaoUserHB;
		
	}

	// ================  Objets métiers  =============== //

	/**
	 * the user.
	 */
	private User user;
	
	/**
	 * Config (session bean).
	 */
	private Config config; 
	
	
	
	// ================  Classic struts methods  =============== //	
	
	

	/** (non-Javadoc).
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 * @return SUCCESS.
	 */
	public final String execute() {
		// nothing for the moment
		return SUCCESS;
	}

	
	// ================  implemented struts methods  =============== //	


	
	
	
	
	// ================ current struts methods ===================== //


	/**
	 * @return String
	 */

	public final String home() {
		
	//	user = new User();
	//	user.setName("toto");
		
	//	this.iDaoUserHB.save(user);


		return SUCCESS;
	}




	// Get & set

	/**
	 * @return the user
	 */
	public final User getUser() {
		return user;
	}


	/**
	 * @param puser the user to set
	 */
	public final void setUser(final User puser) {
		this.user = puser;
	}



	/**
	 * @return the config
	 */
	public final Config getConfig() {
		return config;
	}




	/**
	 * @param config the config to set
	 */
	public void setConfig(Config config) {
		this.config = config;
	}	

	public final String searchUser() {

		user = new  User();

		user.setId(2);
		user.setLogin("youpi");

		setUser(user);

		LOG.info("oh !" + user);

		return SUCCESS;
	}

}
